﻿@*@model IEnumerable<MVC3MusicStore.ViewModels.ShoppingCartViewModel>*@
@model MVC3MusicStore.ViewModels.ShoppingCartViewModel
@{ 
    ViewBag.Title = "购物车";
    ViewBag.Active = "ShoppingCart";
    Layout = "~/Views/Shared/_mPageing.cshtml";
}

<script type="text/javascript">
    $(function () {
        $(".RemoveLink").click(function () {
            var recordToDelete = $(this).attr("data-id");
            if (recordToDelete != '') {
                $.post("/ShoppingCart/RemoveFromCart", { "id": recordToDelete },
                function (data) {
                    if (data.ItemCount == 0) {
                        $('#row-' + data.DeleteId).fadeOut('slow');
                    } else {
                        $('#item-count-' + data.DeleteId).text(data.ItemCount);
                    }
                    $('#cart-total').text(data.CartTotal);
                    $('#update-message').text(data.Message);
                    $('#cart-status').text('Cart (' + data.CartCount + ')');
                });
            }
        });
    });
    function handleUpdate() {
        // Load and deserialize the returned JSON data
        var json = context.get_data();
        var data = Sys.Serialization.JavaScriptSerializer.deserialize(json);
        // Update the page elements
        if (data.ItemCount == 0) {
            $('#row-' + data.DeleteId).fadeOut('slow');
        } else {
            $('#item-count-' + data.DeleteId).text(data.ItemCount);
        }
        $('#cart-total').text(data.CartTotal);
        $('#update-message').text(data.Message);
        $('#cart-status').text('Cart (' + data.CartCount + ')');
    }
</script>
<h3>
    <em>预览</em>您购物车:
</h3>
<p>
    <a data-role="button" data-icon="delete"  href="/Checkout/AddressAndPayment">退出 &gt;&gt;</a>
</p>
<div id="update-message">
</div>
<table class="table table-striped table-bordered table-condensed">
    <thead>
        <tr>
            <th>Album Name
            </th>
            <th>Price (each)
            </th>
            <th>Quantity
            </th>
            <th></th>
        </tr>
    </thead>
    <tbody>
        @foreach (var item in Model.CartItems)
        { <tr id="row-@item.RecordId">
            <td>
                @Html.ActionLink(item.Album.Title, "Details", "Store", new { id = item.AlbumId }, null)
            </td>
            <td>
                @item.Album.Price
            </td>
            <td id="item-count-@item.RecordId">
                @item.Count
            </td>
            <td>
                <a href="#" class="RemoveLink" data-id="@item.RecordId">Remove from cart</a>
            </td>
        </tr>
        }
        <tr>
            <td>Total
            </td>
            <td></td>
            <td></td>
            <td id="cart-total">
                @Model.CartTotal
            </td>
        </tr>
    </tbody>
</table>

